Repository navigation
fix: use fish long options for multi-character flag names - #2453
Conversation
fish reads the argument of complete -s as a group of one-character options. The fish completion generator wrote every name after the first as -s and the first name as -l, so an alias such as fl became the options f and l instead of --fl, and a one-character name was registered as --o. Write a name as -s only when it is a single character and as -l otherwise.
|
Juneezee
left a comment
There was a problem hiding this comment.
LGTM, thanks!
I also checked it with fish 4.9.3, using the flags from the new test:
complete -C 'greet --lo' # main: (nothing) PR: --loud
complete -C 'greet -l' # main: -ld -lo -lp -lt -lu -lv PR: --loud
complete -C 'greet --ou' # main: (nothing) PR: --out --output
prefixFor uses the same one-character rule for help output, so completion now matches what help prints (--verbose, --loud, -v and -o string, --output string, --out string):
Lines 11 to 19 in 2f64589
A small note on the description, no change to the code needed: "Flags whose names are all one character ... generate the same output as before" is not quite right. A flag with only Name: "x" changes from -l x to -s x. That is the intended fix (the same as the o case), and the release note already covers it.
What type of PR is this?
What this PR does / why we need it:
ToFishCompletionwrites the first name of a flag as-land every other name as-s. fish reads the argument ofcomplete -sas a group of one-character options, so an alias with more than one character is registered as several unrelated short options instead of one long option, and a one-character first name is registered as a long option.For
Name: "verbose", Aliases: []string{"loud", "v"}the generated line was-l verbose -s loud -s v. With fish 3.7.0 on the old output,complete -C 'greet --lo'returns nothing andcomplete -C 'greet -l'offers-ld -lo -lp -lt -lu -lv. ForName: "o", Aliases: []string{"output", "out"}the old output registered--oand the short optionso,u,t,p.The generator now uses
-sfor a one-character name and-lfor any other name, whichever position it has in the flag's names. With the change,complete -C 'greet --lo'returns--loudandcomplete -C 'greet --ou'returns--outand--output.fish.go: choose-sor-lper name.testdata/expected-fish-full.fish: theflandsub-flaliases are now-l fland-l sub-fl.fish_test.go: newTestFishCompletionShortAndLongNames.Which issue(s) this PR fixes:
NONE
Special notes for your reviewer:
Not changed on purpose: command aliases are still not offered by the fish completion, and the bash, zsh and PowerShell scripts do not use these options. Flags whose names are all one character, or whose aliases are all one character (the existing help golden file), generate the same output as before.
Testing
make lint,make vet,make test,make test GFLAGS='--tags urfave_cli_no_template',make generate,make diffcheckandmake v3diffpass in a fork run on ubuntu. The new test fails without the change and passes with it. A fork step also sources the generated script in fish 3.7.0 and runscomplete -Cas described above.Release Notes